package com.ruoyi.zhgd.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.Map;

import com.ruoyi.zhgd.util.PageUtils;
import com.ruoyi.zhgd.util.Query;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhgd.domain.vo.TensionRecordingVo;
import com.ruoyi.zhgd.domain.bo.TensionRecordingBo;
import com.ruoyi.zhgd.service.ITensionRecordingService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 张拉记录
 *
 * @author zyb
 * @date 2023-09-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhgd/recording")
public class TensionRecordingController extends BaseController {

    private final ITensionRecordingService iTensionRecordingService;

    /**
     * 查询张拉记录列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<TensionRecordingVo> list(TensionRecordingBo bo, PageQuery pageQuery) {
        return iTensionRecordingService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出张拉记录列表
     */
    @SaCheckLogin
    @Log(title = "张拉记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TensionRecordingBo bo, HttpServletResponse response) {
        List<TensionRecordingVo> list = iTensionRecordingService.queryList(bo);
        ExcelUtil.exportExcel(list, "张拉记录", TensionRecordingVo.class, response);
    }

    /**
     * 获取张拉记录详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<TensionRecordingVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iTensionRecordingService.queryById(id));
    }

    /**
     * 新增张拉记录
     */
    @SaCheckLogin
    @Log(title = "张拉记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TensionRecordingBo bo) {
        return toAjax(iTensionRecordingService.insertByBo(bo));
    }

    /**
     * 修改张拉记录
     */
    @SaCheckLogin
    @Log(title = "张拉记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TensionRecordingBo bo) {
        return toAjax(iTensionRecordingService.updateByBo(bo));
    }

    /**
     * 删除张拉记录
     *
     * @param ids 主键串
     */
    @SaCheckLogin
    @Log(title = "张拉记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iTensionRecordingService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 张拉报表基础信息
     */
    @SaCheckLogin
    @GetMapping("/listMap")
    public Map<String, Object> listMap(@RequestParam Map<String,Object> params) {
        return iTensionRecordingService.listMap(params);
    }

    /***
     * 张拉数据列表
     * @param params
     * @param pageNum
     * @param pageSize
     * @return
     */
    @SaCheckLogin
    @GetMapping("/tensionRecordingList")
    public R  tensionList(@RequestParam Map<String,Object> params,
                          @RequestParam(value = "pageNum" , required = false) Integer pageNum,
                          @RequestParam(value = "pageSize" , required = false) Integer pageSize){
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page",pageNum);
        paramMap.put("limit",pageSize);
        PageUtils tensionList = iTensionRecordingService.tensionList(new Query(paramMap).getPage(), params);
        return R.ok(tensionList);
    }

}
